package com.mingqijia.gassafety.console.controller;

import com.alibaba.fastjson.JSONObject;
import com.gap.basic.base.CommonResponse;
import com.mingqijia.gassafety.webserver.request.BrowserNotifyItemRequest;
import com.mingqijia.gassafety.webserver.response.SmallBellResponse;
import com.mingqijia.gassafety.webserver.service.BrowserNotifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 本地消息
 *
 * @author guoliang.lao
 * @since 2022-02-28
 */

@Slf4j
@Api(tags = "本地消息")
@RestController(value = "BrowserNotifyController")
@RequestMapping("")
public class BrowserNotifyController {

    @Autowired
    BrowserNotifyService browserNotifyService;

    @ApiOperation("本地消息通知接收")
    @RequestMapping(value = "/inner/v1/browser/notify", method = RequestMethod.POST)
    public CommonResponse<Object> notify(@RequestBody List<BrowserNotifyItemRequest> items){
        log.info("本地消息通知接收"+items.toString());
        browserNotifyService.notify(items);
        return CommonResponse.success(null);
    }

    /**
     * job服务本地消息通知触发
     * @return
     */
    @ApiOperation("job本地消息通知触发")
    @RequestMapping(value = "/inner/v1/browser/jobNotify", method = RequestMethod.POST)
    public CommonResponse<Object> jobNotify(@RequestBody JSONObject object){
        log.info("job本地消息通知触发:"+object);
        browserNotifyService.jobNotify(object);
        return CommonResponse.success(null);
    }

    /**
     * 报警小铃铛列表
     * @return
     */
    @ApiOperation("报警小铃铛列表")
    @RequestMapping(value = "/business/v1/browser/smallBellList", method = RequestMethod.GET)
    public CommonResponse<SmallBellResponse> smallBellList() {
        return CommonResponse.success(browserNotifyService.smallBellList());
    }

//    @RequestMapping(value = "/inner/v1/browser/setSmallBell", method = RequestMethod.POST)
//    public CommonResponse<Object> setSmallBell(@RequestBody JSONObject json){
//        Dtu equipment = new Dtu();
//        equipment.setIMEI(json.get("imei").toString());
//        equipment.setEquipmentType(json.get("equipmentType").toString());
//        equipment.setPath(json.get("path").toString());
//        equipment.setSpId(json.get("spId").toString());
//        equipment.setConsumerId(Integer.parseInt(json.get("consumerId").toString()));
//        browserNotifyService.updateSmallBell(equipment,json.get("notifyTime").toString());
//        return CommonResponse.success(null);
//    }
}

